<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../../vue.js"></script>
    <title>Document</title>
</head>
    <style>
        [v-cloak]{
            display: none;
        }
    </style>
<body>
    <!-- 
        v-once指令:
            1.v-once所在节点在动态渲染后,就视为静态内容了.
            2.以后数据的改变不会引起v-once所在解构的更新,可以用于优化性能
     -->
    <div id="root">
        <h2 v-once v-cloak>初始化n值:{{n}}</h2>
        <h2>当前n值:{{n}}</h2>
        <button @click="add">点击n+1</button>
    </div>
</body>
<script>
    const vm = new Vue({
        data: {
            n: 1
        },
        methods: {
            add() {
                return this.n++
            }
        },
    }).$mount('#root')
</script>

</html>